<template>
  <view class="container">
    <view class="prototype-container">
      <view class="prototype">
        <!-- 状态栏 -->
        <view class="status-bar">
          <view class="time">{{currentTime}}</view>
          <view class="status-icons">
            <text>●●●</text>
            <text>📶</text>
            <text>🔋</text>
          </view>
        </view>
        
        <!-- 头部 -->
        <view class="header">
          <view class="logo-section">
            <view class="logo">
              <text style="color: #2989d8; font-size: 20px;">护</text>
            </view>
            <view class="app-name">智慧护理</view>
          </view>
          <view class="header-right">
            <text class="header-icon" @click="navigateToSettings">⚙️</text>
            <text class="header-icon">⊙</text>
          </view>
        </view>
        
        <!-- 活动信息 -->
        <view class="event-info">
          <view style="display: flex; align-items: flex-start;">
            <view class="year-badge">
              2024
            </view>
            <view>
              <view class="event-title">全国护理管理学术会议</view>
              <view class="event-subtitle">前沿护理 创新管理</view>
            </view>
          </view>
          <view class="event-location">中国 · 合肥 | 2024.11.07-08</view>
        </view>
        
        <!-- 轮播广告 -->
        <view class="banner-wrapper">
          <ad-banner></ad-banner>
        </view>
        
        <!-- 菜单网格 -->
        <view class="menu-grid">
          <view class="menu-item" v-for="(item, index) in menuItems.slice(0, 7)" :key="index" @click="handleItemClick(item)">
            <view class="menu-icon">📄</view>
            <view class="menu-text">{{item.title}}</view>
          </view>
          <!-- 我的按钮 -->
          <view class="menu-item" @click="navigateToIndexPage">
            <view class="menu-icon">👤</view>
            <view class="menu-text">我的</view>
          </view>
        </view>
        
        <!-- 底部 -->
        <view class="footer">
          <view class="footer-text">【主办单位】</view>
          <view class="footer-text">中国护理管理协会</view>
          <view class="footer-text">【承办单位】</view>
          <view class="footer-text">合肥医科大学附属第一医院</view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import AdBanner from '@/components/AdBanner.vue'

export default {
  components: {
    AdBanner
  },
  data() {
    return {
      currentTime: '9:41',
      menuItems: [
  {
    title: '大会通知',
    path: '/pages/conference/notice'
  },
  {
    title: '大会日程',
    path: '/pages/conference/schedule'
  },
  {
    title: '专家风采',
    path: '/pages/conference/expert'
  },
  {
    title: '参会报名',
    path: '/pages/conference/register'
  },
  {
    title: '酒店预订',
    path: '/pages/accommodation/reser_index'
  },
  {
    title: '线上考试',
    path: '/pages/conference/exam'
  },
  {
    title: '在线直播',
    path: '/pages/conference/live'
  },
  {
    title: '联系我们',
    path: '/pages/conference/contact'
  }
      ],
      gradientColors: {
        primary: '#1e5799',
        secondary: '#2989d8',
        tertiary: '#207cca'
      }
    }
  },
  mounted() {
    this.updateTime()
    setInterval(this.updateTime, 1000)
    this.loadBackgroundColor()
    
    // 监听背景颜色更新事件
    uni.$on('updateBackgroundColor', this.handleBackgroundColorUpdate)
  },
  beforeDestroy() {
    // 移除事件监听
    uni.$off('updateBackgroundColor', this.handleBackgroundColorUpdate)
  },
  methods: {
    updateTime() {
      const now = new Date()
      const hours = now.getHours().toString().padStart(2, '0')
      const minutes = now.getMinutes().toString().padStart(2, '0')
      this.currentTime = `${hours}:${minutes}`
    },
    navigateToSettings() {
      uni.navigateTo({
        url: '/pages/settings/settings'
      })
    },
    handleItemClick(item) {
      try {
        uni.navigateTo({
          url: item.path,
          success: () => {
            console.log('页面跳转成功：', item.title);
          },
          fail: (err) => {
            console.error('页面跳转失败：', err);
            uni.showToast({
              title: '页面跳转失败',
              icon: 'none'
            });
          }
        });
      } catch (error) {
        console.error('页面跳转异常：', error);
        uni.showToast({
          title: '系统异常',
          icon: 'error'
        });
      }
    },
    navigateToIndexPage() {
      try {
        uni.switchTab({
          url: '/pages/index/index',
          fail: (err) => {
            console.error('切换到"我的"页面失败：', err);
            uni.redirectTo({
              url: '/pages/index/index',
              fail: (redirectErr) => {
                console.error('重定向到"我的"页面失败：', redirectErr);
                uni.reLaunch({
                  url: '/pages/index/index'
                });
              }
            });
          }
        });
      } catch (error) {
        console.error('跳转异常：', error);
      }
    },
    loadBackgroundColor() {
      // 从本地存储加载保存的背景颜色
      const savedColor = uni.getStorageSync('appBackgroundColor')
      if (savedColor) {
        this.updateGradientColors(savedColor)
      }
    },
    handleBackgroundColorUpdate(color) {
      this.updateGradientColors(color)
    },
    updateGradientColors(baseColor) {
      // 根据基础颜色生成渐变色
      this.gradientColors.primary = baseColor
      
      // 计算次要颜色（稍微亮一些）
      const lighterColor = this.lightenColor(baseColor, 20)
      this.gradientColors.secondary = lighterColor
      
      // 计算第三颜色（稍微暗一些）
      const darkerColor = this.darkenColor(baseColor, 10)
      this.gradientColors.tertiary = darkerColor
    },
    lightenColor(color, percent) {
      const num = parseInt(color.replace('#', ''), 16)
      const amt = Math.round(2.55 * percent)
      const R = (num >> 16) + amt
      const G = (num >> 8 & 0x00FF) + amt
      const B = (num & 0x0000FF) + amt
      return '#' + (
        0x1000000 +
        (R < 255 ? (R < 1 ? 0 : R) : 255) * 0x10000 +
        (G < 255 ? (G < 1 ? 0 : G) : 255) * 0x100 +
        (B < 255 ? (B < 1 ? 0 : B) : 255)
      ).toString(16).slice(1)
    },
    darkenColor(color, percent) {
      const num = parseInt(color.replace('#', ''), 16)
      const amt = Math.round(2.55 * percent)
      const R = (num >> 16) - amt
      const G = (num >> 8 & 0x00FF) - amt
      const B = (num & 0x0000FF) - amt
      return '#' + (
        0x1000000 +
        (R > 0 ? (R > 255 ? 255 : R) : 0) * 0x10000 +
        (G > 0 ? (G > 255 ? 255 : G) : 0) * 0x100 +
        (B > 0 ? (B > 255 ? 255 : B) : 0)
      ).toString(16).slice(1)
    }
  }
}
</script>

<style>
/* 容器 */
.container {
  min-height: 100vh;
  background-color: #f5f7fa;
  padding: 20px;
}
/* 原型 */
.prototype-container {
  width: 375px;
  height: 812px;
  margin: 0 auto;
  border-radius: 40px;
  overflow: hidden;
  position: relative;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  border: 10px solid #000;
  background-color: #fff;
}

.prototype {
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: relative;
  background: linear-gradient(to bottom, v-bind('gradientColors.primary'), v-bind('gradientColors.secondary'), v-bind('gradientColors.tertiary'));
  transition: background 0.3s ease;
}
/* 状态栏 */
.status-bar {
  height: 44px;
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  color: white;
  font-size: 14px;
  font-weight: 600;
}
/* 时间 */
  .time {
    font-weight: bold;
  }
/* 状态图标 */
  .status-icons {
    display: flex;
  gap: 5px;
}

.header {
  padding: 15px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
/* 标志 */
  .logo-section {
    display: flex;
    align-items: center;
}
/* 标志 */
    .logo {
  width: 36px;
  height: 36px;
  background-color: white;
  border-radius: 50%;
      display: flex;
  align-items: center;
      justify-content: center;
  margin-right: 10px;
    }
/* 标志 */
    .app-name {
  color: white;
  font-size: 18px;
  font-weight: bold;
    }
/* 标志 */
  .header-right {
    display: flex;
  align-items: center;
  background-color: rgba(255, 255, 255, 0.2);
  border-radius: 20px;
  padding: 5px 10px;
}
/* 标志 */
    .header-icon {
  color: white;
  margin: 0 5px;
  font-size: 18px;
    }
/* 事件信息 */
.event-info {
  padding: 15px 20px;
  color: white;
  text-align: left;
}
/* 年份徽章 */
  .year-badge {
  font-size: 32px;
  font-weight: bold;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
}
/* 年份徽章 */
.year-badge::after {
  content: "";
  width: 1px;
  height: 30px;
  background-color: rgba(255, 255, 255, 0.5);
  margin: 0 15px;
  }
/* 事件标题 */
  .event-title {
  font-size: 20px;
  font-weight: bold;
  margin-bottom: 5px;
  }
/* 事件副标题 */
  .event-subtitle {
  font-size: 16px;
  margin-bottom: 5px;
  }
/* 事件地点 */  
  .event-location {
  font-size: 14px;
  opacity: 0.9;
  }
/* 菜单 */
.menu-grid {
  padding: 10px 20px 20px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  grid-gap: 15px;
  margin-top: 10px;
  max-height: 220px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
}
/* 菜单滚动条 */
.menu-grid::-webkit-scrollbar {
  width: 6px;
}
/* 菜单滚动条轨道 */
.menu-grid::-webkit-scrollbar-track {
  background: transparent;
}
/* 菜单滚动条滑块 */
.menu-grid::-webkit-scrollbar-thumb {
  background-color: rgba(255, 255, 255, 0.3);
  border-radius: 3px;
}
/* 菜单 */
  .menu-item {
  background-color: rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  padding: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  color: white;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s;
  height: 100px;
}
/* 菜单点击 */
.menu-item:active {
  background-color: rgba(255, 255, 255, 0.3);
  transform: translateY(-3px);
    }
/* 菜单图标 */
    .menu-icon {
  font-size: 24px;
  margin-bottom: 10px;
      }
/* 菜单文字 */
    .menu-text {
  font-size: 16px;
  font-weight: bold;
    }
/* 底部 */
.footer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 15px 20px;
  color: white;
  text-align: center;
  font-size: 12px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1440 320'%3E%3Cpath fill='%23000' fill-opacity='0.2' d='M0,224L80,213.3C160,203,320,181,480,181.3C640,181,800,203,960,213.3C1120,224,1280,224,1360,208L1440,192L1440,320L1360,320C1280,320,1120,320,960,320C800,320,640,320,480,320C320,320,160,320,80,320L0,320Z'%3E%3C/path%3E%3C/svg%3E");
  background-size: cover;
  background-position: center top;
  height: 100px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  z-index: 5;
}
/* 底部文字 */
  .footer-text {
  margin-bottom: 5px;
}

/* 轮播广告包装器 */
.banner-wrapper {
  padding: 0 20px;
  margin: 5px 0 15px 0;
}
</style> 